package com.codejam2013.qualification;
import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;


public class A {

	static int nTest;
	static String[] board = new String[4];
	
	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("A-in.txt"));
		PrintStream ps = new PrintStream(new File("A-out.txt"));
		System.setOut(ps);
		nTest = scanner.nextInt();
		
		for (int test=1;test<=nTest;++test) {
			System.out.print("Case #" + test + ": ");
			for (int i=0;i<4;++i) {
				board[i] = scanner.next();
			}
			//scanner.nextLine();
			if (check('X')) {
				System.out.println("X won");
			}
			else if (check('O')) {
				System.out.println("O won");
			}
			else if (!empty()) {
				System.out.println("Draw");
			}
			else {
				System.out.println("Game has not completed");
			}
		}
	}

	private static boolean empty() {
		for (int i=0;i<4;++i) {
			for (int j=0;j<4;++j) {
				char c = board[i].charAt(j);
				if (c == '.') {
					return true;
				}
			}
		}
		return false;
	}

	private static boolean check(char player) {
		for (int i=0;i<4;++i) {
			if (checkRow(player,i)) {
				return true;
			}
			else if (checkCol(player,i)) {
				return true;
			}
		}
		if (checkFirstDia(player)) {
			return true;
		}
		else if (checkSecondDia(player)) {
			return true;
		}
		else {
			return false;
		}
	}

	private static boolean checkCol(char player, int c) {
		for (int i=0;i<4;++i) {
			if (board[i].charAt(c) != player && board[i].charAt(c) != 'T') {
				return false;
			}
		}
		return true;
	}

	private static boolean checkRow(char player, int r) {
		for (int i=0;i<4;++i) {
			if (board[r].charAt(i) != player && board[r].charAt(i) != 'T') {
				return false;
			}
		}
		return true;
	}

	private static boolean checkSecondDia(char player) {
		for (int i=0;i<4;++i) {
			if (board[i].charAt(3-i) != player && board[i].charAt(3-i) != 'T') {
				return false;
			}
		}
		return true;
	}

	private static boolean checkFirstDia(char player) {
		for (int i=0;i<4;++i) {
			if (board[i].charAt(i) != player && board[i].charAt(i) != 'T') {
				return false;
			}
		}
		return true;
	}

}
